package com.jysz.certificate.web.action.system;

import javax.annotation.Resource;

import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Namespace;
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import com.jysz.certificate.action.AbstractBaseAction;
import com.jysz.certificate.constant.OperCodeConstant;
import com.jysz.certificate.persistence.model.dto.FinancialDTO;
import com.jysz.certificate.persistence.model.system.Financial;
import com.jysz.certificate.service.system.FinancialService;
import com.jysz.webcore.ssh.annotation.PermissionPoint;

@Controller
@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
@Namespace("/system/financial")
public class FinancialAction extends AbstractBaseAction {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	@Resource
	private FinancialService financialService;

	private Financial f;
	private FinancialDTO search;

	@Action(INDEX)
	public String index() {
		this.setPage(financialService.selectFinancial(search, getCurrentPage(),
				getPageSize()));
		return "index";
	}

	@Action("toAdd")
	@PermissionPoint(point = OperCodeConstant.SYS_FIN_ADD)
	public String toAdd() {
		return "add";
	}

	@Action("add")
	@PermissionPoint(point = OperCodeConstant.SYS_FIN_ADD)
	public String add() {
		f.setIsDelete("0");
		financialService.save(f);
		setRedirectUrl("index.do?currentPage=" + getCurrentPage(), "search",
				search);
		setSuccessPopMessage("金融机构添加成功");
		return SHOW_MSG_PAGE;
	}

	@Action("toUpdate")
	@PermissionPoint(point = OperCodeConstant.SYS_FIN_EDIT)
	public String toUpdate() {
		f = financialService.getFinancial(f.getId());
		setRedirectUrl("index.do?currentPage=" + getCurrentPage(), "search",
				search);
		return "detail";
	}

	@Action("update")
	@PermissionPoint(point = OperCodeConstant.SYS_FIN_EDIT)
	public String update() {
		financialService.update(f);
		setRedirectUrl("index.do?currentPage=" + getCurrentPage(), "search",
				search);
		setSuccessPopMessage("金融机构修改成功");
		return SHOW_MSG_PAGE;
	}

	@Action("view")
	public String view() {
		f = financialService.getFinancial(f.getId());
		return "view";
	}

	@Action("delete")
	@PermissionPoint(point = OperCodeConstant.SYS_FIN_DEL)
	public String delete() {
		financialService.delete(f.getId());
		setRedirectUrl("index.do?currentPage=" + getCurrentPage(), "search",
				search);
		setSuccessPopMessage("删除金融机构成功");
		return SHOW_MSG_PAGE;
	}

	public Financial getF() {
		return f;
	}

	public void setF(Financial f) {
		this.f = f;
	}

	public FinancialDTO getSearch() {
		return search;
	}

	public void setSearch(FinancialDTO search) {
		this.search = search;
	}

}
